package com.fyj.controller;

import com.fyj.pojo.MyMission;
import com.fyj.pojo.Result;
import com.fyj.pojo.ResultCode;
import com.fyj.pojo.User;
import com.fyj.service.AdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 钰杰
 * @className AdminController
 * @description VX:FengYJ996
 * @date 2019/12/611:22
 */
@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admincontroller")
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * 获取任务列表信息
     *
     * @return
     */
    @ApiOperation(value = "获取任务列表信息", notes = "获取全部任务列表")
    @ApiImplicitParam(value = "获取任务列表")
    @GetMapping(value = "/getMissionAll")
    public Result getMissionAll() {
        List<MyMission> allMission = adminService.getAllMission();
        if (allMission != null) {
            return new Result(true, ResultCode.SUCCESS_CODE, "任务列表", allMission);
        } else {
            return new Result(false, ResultCode.ERROR_DBA_SHOW_MISSION_CODE, "获取任务列表失败", null);
        }
    }

    /**
     * 审核任务
     *
     * @param missionids 任务编号
     * @param updtsatus  审核状态
     * @return
     */
    @ApiOperation(value = "审核任务状态", notes = "管理员审核任务状态")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "missionids", value = "任务编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "userid", value = "用户编号", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "updtsatus", value = "状态标示号", required = true, dataType = "Integer")
    })
    @PostMapping(value = "/examineMission/{missionids}/{updtsatus}/")
    public Result examineMission(@PathVariable("missionids") Integer missionids,
                                 @PathVariable("userid") Integer userid,
                                 @PathVariable("updtsatus") Integer updtsatus) {

        int code = adminService.examineMission(missionids + "", updtsatus + "", userid);
        if (code == 5301) {
            return new Result(true, ResultCode.ERROR_ADMIN_EXAMINE_MISSION_CODE, "修改失败！", null);
        } else {
            return new Result(true, ResultCode.SUCCESS_CODE, "修改成功", null);
        }

    }

    /**
     * 按权重降序排序
     *
     * @return
     */
    @ApiOperation(value = "获取任务信息按权重排序", notes = "根据权重降序排序获取任务列表")
    @ApiImplicitParam(value = "获取任务信息按权重排序")
    @GetMapping(value = "/getMissionByLevel")
    public Result getMissionByLevel() {
        return new Result(true, ResultCode.SUCCESS_CODE, "按权重降序排序", adminService.getMissionByLevel());
    }

    /**
     * 按时间升序排序
     *
     * @return
     */
    @ApiOperation(value = "获取任务信息按创建时间排序", notes = "根据创建时间升序排序获取任务列表")
    @ApiImplicitParam(value = "获取任务信息按创建时间排序")
    @GetMapping(value = "/getMissionByCdate")
    public Result getMissionByCdate() {
        return new Result(true, ResultCode.SUCCESS_CODE, "按时间升序排序", adminService.getMissionByCdate());
    }

    /**
     * 修改用户
     *
     * @param user
     * @return
     */
    @ApiOperation(value = "修改用户信息", notes = "修改用户信息")
    @GetMapping(value = "/updUserInfo")
    @ApiImplicitParam(name = "user", value = "用户信息", required = true, dataType = "User")
    public Result updUserInfo(@RequestBody User user) {
        adminService.updUser(user);
        return new Result(true, ResultCode.SUCCESS_CODE, "修改成功", null);
    }


    /**
     * 获取用户列表
     *
     * @return
     */
    @ApiOperation(value = "获取用户列表", notes = "获取用户列表")
    @ApiImplicitParam(value = "获取用户列表")
    @GetMapping(value = "/getUserList")
    public Result getUserList() {
        return new Result(true, ResultCode.SUCCESS_CODE, "用户列表", adminService.findUserList());
    }

}